package cn.itsource;

import cn.itsource.domain.User;
import cn.itsource.fegin.client.UserFeignClient;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
//@DefaultProperties(defaultFallback = "defaultFallbackMethod") //统一降级配置
@RestController
public class PayController {


    @Autowired
    UserFeignClient userFeignClient;

    @GetMapping("pay/{id}")
    @HystrixCommand(fallbackMethod = "fallbackMethod")//方法熔断
    public User test(@PathVariable Long id){

        User userById = userFeignClient.getUserById(id);
        return userById;
    }

    //托底方法
    public User fallbackMethod(@PathVariable("id")Long id){
        //在返回 托底结果的同时，是不是也可以向【运维人员】发送通知
        //返回托底数据,友好的提示信息
        return new User(-1L ,"无此用户,用户服务不可用，执行托底方法");
    }
    //统一降级配置-托底方法
    public User defaultFallbackMethod(){
        //返回托底数据,友好的提示信息
        return new User(-1L ,"无此用户,用户服务不可用，执行托底方法 | 统一降级配置");
    }
}
